﻿<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>
            企业进销存系统
        </title>
        <link rel="stylesheet" href="./css/common.css" type="text/css" media="screen"/>
        <script type="text/javascript" src="./js/jquery-1.8.3.min.js"></script> 
    </head>
    
    <body >
        <form id="mpwd">
            <label class="pwdl">真实姓名：</label><input type='text' id='adminrname'/><br>
            <label class="pwdl">用户名：</label><input type='text' id='adminuname'/><br>
            <lable class="pwdl">类型:</lable>
            <select id="type" style="margin-left:-5px">
                <option>超级管理员</option>
                <option>供应商管理员</option>
                <option>订单管理员</option>
                <option>仓库管理员</option>
            </select>
            <label class="pwdl">管理员密码：</label><input type='password' id='adminopwd'/><br>
            <label class="pwdl">确认密码：</label><input type='password' id='adminnpwd'/><br>
            <label class="pwdl">备注：</label><textarea id="remarks"></textarea>
            <div style="text-align:center;width:250px">
                <div class="button" style="" onclick='clickLog();' >添加管理</div>
                <button type="reset" class="pwdb" id="cancelpwd">取消操作</button>
            </div>

        </form>
        
    </body>
    <script>
        function clickLog() {
            //alert($('#type').val());
            type=0;
            switch($('#type').val()){
                case "超级管理员":type=0;break;
                case "供应商管理员":type=1;break;
                case "订单管理员":type=2;break;
                case "仓库管理员":type=3;break;
            }
            alert(type);

            if($('#adminrname').val()===""||$('#adminuname').val()===""||$('#adminopwd').val()===""
                ||$('#adminnpwd').val()===""){
                alert("请填满除备注以外的所有内容");
            } 

            else if($('#adminopwd').val()===$('#adminnpwd').val()){
                $.ajax({
                    type : "POST",
                    url : "/jxc/addadmin.do",
                    async:false,
                    data:{
                        "userid":$('#adminuname').val(),
                        "pwd":$('#adminopwd').val(),
                        "name":$('#adminrname').val(),
                        "bz":$('#remarks').val(),
                        "type":type
                    },
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    dataType : 'json',
                    success : function(data) {
                        //alert(data.result);
                        if(data.result===1){
                            alert("用户名已存在请重新输入");
                            $('#adminuname').val("");
                            $('#adminopwd').val("");
                            $('#adminnpwd').val("");
                        }else{
                            alert("添加成功");
                            location.href='';
                        }
                        
                    },
                    error : function(data) {
                       alert("error");
                    }            
                      
                });

            }else{
                alert("两次输入的密码不一致");
            }   
        }
    </script>

</html>